<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }

        .el-dropdown + .el-dropdown {
            margin-left: 15px;
        }

    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约列表</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="姓名/手机号/预约套餐/预约状态" v-model="pagination.queryString" style="width: 240px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="select()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column  type="index" label="序号" align="center" ></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column label="性别" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                </el-table-column>
                <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                <el-table-column prop="setmeal" label="预约套餐" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" round @click="affirm(scope.row)">确认就诊</el-button><br/>
                        <el-button size="mini" type="danger" round @click="cancel(scope.row)">取消就诊</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="预约日期" prop="orderDate">
                                    <template>
                                        <div class="block">
                                            <el-date-picker
                                                    v-model="formData.orderDate"
                                                    type="date"
                                                    placeholder="选择日期"
                                                    format="yyyy 年 MM 月 dd 日">
                                            </el-date-picker>
                                        </div>
                                    </template>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="姓名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="性别" prop="sex">
                                    <el-select v-model="formData.sex">
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="预约套餐" prop="setmeal.name">
                                    <el-select v-model="setmeal.name" clearable placeholder="选择预约套餐">
                                        <el-option
                                                v-for="item in setmeal"
                                                :key="item.id"
                                                :label="item.name"
                                                :value="item.id"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="就诊地址" prop="address.name">
                                    <el-select v-model="address.name" clearable placeholder="选择就诊地址">
                                        <el-option
                                                v-for="item in address"
                                                :key="item.id"
                                                :label="item.name"
                                                :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="预约类型" prop="orderType">
                                    <el-select v-model="formData.orderType">
                                        <el-option label="微信预约" value="微信预约"></el-option>
                                        <el-option label="电话预约" value="电话预约"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="手机号码" prop="telephone">
                                    <el-input v-model="formData.telephone"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="身份证号码" prop="idCard">
                                    <el-input v-model="formData.idCard"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="说明">
                                    <el-input v-model="formData.remark" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>


<script>

    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            dataList:[],
            formData: {},//表单数据
            setmeal: {},
            address: {},
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            rules: {//校验规则
                name: [{required: true, message: '角色名为必填项', trigger: 'blur'}],
                telephone: [{required: true, message: '手机号为必填项', trigger: 'blur'}],
                idCard: [{required: true, message: '身份证为必填项', trigger: 'blur'}],
                orderDate: [{required: true, message: '预约日期为必填项', trigger: 'blur'}],
                sex: [{required: true, message: '性别为必填项', trigger: 'blur'}],
                setmeal: [{required: true, message: '套餐为必填项', trigger: 'blur'}],
                address: [{required: true, message: '地址为必填项', trigger: 'blur'}],
                orderType: [{required: true, message: '预约类型为必填项', trigger: 'blur'}]
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            //添加
            handleAdd() {
                var phoneNumber= this.formData.telephone;
                if (!checkTelephone(phoneNumber)) {
                    //手机号校验不通过
                    this.$message.error("请输入正确的手机号");
                    return false;
                }
                var idCard= this.formData.idCard;
                if (!checkIdCard(idCard)) {
                    //手机号校验不通过
                    this.$message.error("请输入正确的身份证号码");
                    return false;
                }
                this.$refs['dataAddForm'].validate((vali) => {
                    if (vali) {
                        axios.post("/orderList/add.do?setmealId=" + this.setmeal.name + "&addressId=" + this.address.name, this.formData).then((res) => {
                            if (res.data.flag){
                                this.$message.success(res.data.message);
                            } else {
                                this.$message.error(res.data.message);
                            }
                        }).finally(()=>{
                            this.dialogFormVisible = false;
                            this.findPage();
                        })
                    } else {
                        this.$message.error("请填写完整信息")
                    }
                })
            },
            select(){
              this.pagination.currentPage=1;
              this.findPage();
            },
            //分页查询
            findPage() {
                var parm = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/orderList/findPage.do", parm).then((res) => {
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                })
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.setmeal= {};
                this.address= {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
                //发送ajax请求查询所有套餐
                axios.get("/setmeal/findAll.do").then((res) => {
                    if (res.data.flag) {
                        this.setmeal = res.data.data;
                    } else {
                        this.$message.error(res.data.message)
                    }
                });
                //发送ajax请求查询所有地址
                axios.post("/setmeal/findAllAddress.do").then((res) => {
                    if (res.data.flag) {
                        this.address = res.data.data;
                    } else {
                        this.$message.error(res.data.message)
                    }
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            affirm(row) {
                this.$confirm("是否确认?","温馨提示",{
                    type:'warning'
                }).then(()=>{
                    axios.post("/orderList/update1.do?id="+ row.id).then((res)=>{
                        if (res.data.flag){
                            this.$message.success(res.data.message)
                        } else {
                            this.$message.error(res.data.message)
                        }
                    }).finally(()=>{
                        this.findPage();
                    })
                }).catch(()=>{
                    this.$message.info("操作已取消")
                });
            },
            cancel(row) {
                this.$confirm("确认取消预约吗?","温馨提示",{
                    type:'warning'
                }).then(()=>{
                    axios.post("/orderList/update2.do?id="+ row.id).then((res)=>{
                        if (res.data.flag){
                            this.$message.success(res.data.message)
                        } else {
                            this.$message.error(res.data.message)
                        }
                    }).finally(()=>{
                        this.findPage();
                    })
                }).catch(()=>{
                    this.$message.info("操作已取消")
                });
            }
        }
    })
</script>
</html>
